using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace etbTOEIC
{
	/// <summary>
	/// Summary description for FormConfig.
	/// </summary>
	public class FormConfig : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPageSection;
		private System.Windows.Forms.TabPage tabPagereport;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.ListView lvSections;
	
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Button btnClose;
		private etbTOEIC.UCSectionInfo ucSectionInfo1;
		private System.Windows.Forms.CheckBox checkBoxSchool;
		private System.Windows.Forms.CheckBox checkBoxclass;
		private System.Windows.Forms.CheckBox checkBoxpagenumber;
		private System.Windows.Forms.CheckBox checkBoxexamcode;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtReportHeader;
		private System.Windows.Forms.TextBox txtReportFooter;
		private System.Windows.Forms.TextBox txtPageDirection;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormConfig()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormConfig));
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.tabPageSection = new System.Windows.Forms.TabPage();
			this.ucSectionInfo1 = new etbTOEIC.UCSectionInfo();
			this.btnSave = new System.Windows.Forms.Button();
			this.lvSections = new System.Windows.Forms.ListView();
			this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.tabPagereport = new System.Windows.Forms.TabPage();
			this.btnClose = new System.Windows.Forms.Button();
			this.checkBoxSchool = new System.Windows.Forms.CheckBox();
			this.checkBoxclass = new System.Windows.Forms.CheckBox();
			this.checkBoxpagenumber = new System.Windows.Forms.CheckBox();
			this.checkBoxexamcode = new System.Windows.Forms.CheckBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtReportHeader = new System.Windows.Forms.TextBox();
			this.txtReportFooter = new System.Windows.Forms.TextBox();
			this.txtPageDirection = new System.Windows.Forms.TextBox();
			this.tabControl1.SuspendLayout();
			this.tabPageSection.SuspendLayout();
			this.tabPagereport.SuspendLayout();
			this.SuspendLayout();
			// 
			// tabControl1
			// 
			this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.tabControl1.Controls.Add(this.tabPageSection);
			this.tabControl1.Controls.Add(this.tabPagereport);
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(560, 272);
			this.tabControl1.TabIndex = 0;
			// 
			// tabPageSection
			// 
			this.tabPageSection.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPageSection.BackgroundImage")));
			this.tabPageSection.Controls.Add(this.ucSectionInfo1);
			this.tabPageSection.Controls.Add(this.lvSections);
			this.tabPageSection.Controls.Add(this.groupBox1);
			this.tabPageSection.Location = new System.Drawing.Point(4, 25);
			this.tabPageSection.Name = "tabPageSection";
			this.tabPageSection.Size = new System.Drawing.Size(552, 243);
			this.tabPageSection.TabIndex = 0;
			this.tabPageSection.Text = "Section";
			// 
			// ucSectionInfo1
			// 
			this.ucSectionInfo1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("ucSectionInfo1.BackgroundImage")));
			this.ucSectionInfo1.Direction = "";
			this.ucSectionInfo1.Location = new System.Drawing.Point(8, 8);
			this.ucSectionInfo1.Name = "ucSectionInfo1";
			this.ucSectionInfo1.Size = new System.Drawing.Size(304, 208);
			this.ucSectionInfo1.TabIndex = 11;
			this.ucSectionInfo1.TheEnd = "";
			this.ucSectionInfo1.Title = "";
			// 
			// btnSave
			// 
			this.btnSave.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.btnSave.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnSave.BackgroundImage")));
			this.btnSave.Location = new System.Drawing.Point(304, 272);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new System.Drawing.Size(96, 32);
			this.btnSave.TabIndex = 10;
			this.btnSave.Text = "&Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// lvSections
			// 
			this.lvSections.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
																						 this.columnHeader1});
			this.lvSections.Location = new System.Drawing.Point(336, 39);
			this.lvSections.Name = "lvSections";
			this.lvSections.Size = new System.Drawing.Size(192, 176);
			this.lvSections.TabIndex = 7;
			this.lvSections.View = System.Windows.Forms.View.List;
			this.lvSections.SelectedIndexChanged += new System.EventHandler(this.lvSections_SelectedIndexChanged);
			// 
			// columnHeader1
			// 
			this.columnHeader1.Text = "Book Name";
			this.columnHeader1.Width = 200;
			// 
			// groupBox1
			// 
			this.groupBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBox1.BackgroundImage")));
			this.groupBox1.Location = new System.Drawing.Point(320, 7);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(224, 224);
			this.groupBox1.TabIndex = 8;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Book List";
			// 
			// tabPagereport
			// 
			this.tabPagereport.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPagereport.BackgroundImage")));
			this.tabPagereport.Controls.Add(this.txtReportHeader);
			this.tabPagereport.Controls.Add(this.label1);
			this.tabPagereport.Controls.Add(this.checkBoxSchool);
			this.tabPagereport.Controls.Add(this.checkBoxclass);
			this.tabPagereport.Controls.Add(this.checkBoxpagenumber);
			this.tabPagereport.Controls.Add(this.checkBoxexamcode);
			this.tabPagereport.Controls.Add(this.label2);
			this.tabPagereport.Controls.Add(this.label3);
			this.tabPagereport.Controls.Add(this.txtReportFooter);
			this.tabPagereport.Controls.Add(this.txtPageDirection);
			this.tabPagereport.Location = new System.Drawing.Point(4, 25);
			this.tabPagereport.Name = "tabPagereport";
			this.tabPagereport.Size = new System.Drawing.Size(552, 243);
			this.tabPagereport.TabIndex = 1;
			this.tabPagereport.Text = "Report";
			// 
			// btnClose
			// 
			this.btnClose.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.btnClose.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnClose.BackgroundImage")));
			this.btnClose.Location = new System.Drawing.Point(448, 272);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(96, 32);
			this.btnClose.TabIndex = 10;
			this.btnClose.Text = "&Close";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// checkBoxSchool
			// 
			this.checkBoxSchool.BackColor = System.Drawing.Color.Transparent;
			this.checkBoxSchool.Location = new System.Drawing.Point(8, 176);
			this.checkBoxSchool.Name = "checkBoxSchool";
			this.checkBoxSchool.Size = new System.Drawing.Size(256, 24);
			this.checkBoxSchool.TabIndex = 1;
			this.checkBoxSchool.Text = "Show school name at top of each page";
			// 
			// checkBoxclass
			// 
			this.checkBoxclass.BackColor = System.Drawing.Color.Transparent;
			this.checkBoxclass.Location = new System.Drawing.Point(8, 208);
			this.checkBoxclass.Name = "checkBoxclass";
			this.checkBoxclass.Size = new System.Drawing.Size(256, 24);
			this.checkBoxclass.TabIndex = 1;
			this.checkBoxclass.Text = "Show class name at top of each page";
			// 
			// checkBoxpagenumber
			// 
			this.checkBoxpagenumber.BackColor = System.Drawing.Color.Transparent;
			this.checkBoxpagenumber.Location = new System.Drawing.Point(272, 208);
			this.checkBoxpagenumber.Name = "checkBoxpagenumber";
			this.checkBoxpagenumber.Size = new System.Drawing.Size(288, 24);
			this.checkBoxpagenumber.TabIndex = 1;
			this.checkBoxpagenumber.Text = "Show page number at bottom of each page";
			// 
			// checkBoxexamcode
			// 
			this.checkBoxexamcode.BackColor = System.Drawing.Color.Transparent;
			this.checkBoxexamcode.Location = new System.Drawing.Point(272, 176);
			this.checkBoxexamcode.Name = "checkBoxexamcode";
			this.checkBoxexamcode.Size = new System.Drawing.Size(272, 24);
			this.checkBoxexamcode.TabIndex = 1;
			this.checkBoxexamcode.Text = "Show exam code at top of each page";
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Location = new System.Drawing.Point(16, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(152, 23);
			this.label1.TabIndex = 2;
			this.label1.Text = "Report Header :";
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Location = new System.Drawing.Point(16, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(152, 23);
			this.label2.TabIndex = 2;
			this.label2.Text = "Report Footer :";
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.Color.Transparent;
			this.label3.Location = new System.Drawing.Point(16, 120);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(152, 23);
			this.label3.TabIndex = 2;
			this.label3.Text = "Direction between pages";
			// 
			// txtReportHeader
			// 
			this.txtReportHeader.Location = new System.Drawing.Point(176, 8);
			this.txtReportHeader.Multiline = true;
			this.txtReportHeader.Name = "txtReportHeader";
			this.txtReportHeader.Size = new System.Drawing.Size(368, 40);
			this.txtReportHeader.TabIndex = 3;
			this.txtReportHeader.Text = "";
			// 
			// txtReportFooter
			// 
			this.txtReportFooter.Location = new System.Drawing.Point(176, 64);
			this.txtReportFooter.Multiline = true;
			this.txtReportFooter.Name = "txtReportFooter";
			this.txtReportFooter.Size = new System.Drawing.Size(368, 40);
			this.txtReportFooter.TabIndex = 3;
			this.txtReportFooter.Text = "";
			// 
			// txtPageDirection
			// 
			this.txtPageDirection.Location = new System.Drawing.Point(176, 120);
			this.txtPageDirection.Multiline = true;
			this.txtPageDirection.Name = "txtPageDirection";
			this.txtPageDirection.Size = new System.Drawing.Size(368, 40);
			this.txtPageDirection.TabIndex = 3;
			this.txtPageDirection.Text = "";
			// 
			// FormConfig
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 16);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(560, 302);
			this.ControlBox = false;
			this.Controls.Add(this.tabControl1);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnSave);
			this.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "FormConfig";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Configuration";
			this.Load += new System.EventHandler(this.FormConfig_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPageSection.ResumeLayout(false);
			this.tabPagereport.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			if(tabControl1.SelectedTab.Text == "Section")
			{
				if(lvSections.SelectedItems.Count < 1)
					return;
				int nID = Convert.ToInt32(lvSections.SelectedItems[0].Tag.ToString());
				if(!DB2MainForm.UpdateSection(nID, ucSectionInfo1))
					MessageBox.Show("Cannot update section info", "Update Section - Error");
				else
				{
					lvSections.Items.Clear();
					DB2MainForm.LoadSections(lvSections);
				}
			}
			else
			{
				DB2MainForm.isDisplayExamCode = checkBoxexamcode.Checked;
				DB2MainForm.isDisplaySchool = checkBoxSchool.Checked;
				DB2MainForm.isDisplayClass = checkBoxclass.Checked;
				DB2MainForm.isDisplayPageNumber = checkBoxpagenumber.Checked;
				DB2MainForm.stPageDirection = txtPageDirection.Text;
				DB2MainForm.stReportFooter = txtReportFooter.Text;
				DB2MainForm.stReportHeader = txtReportHeader.Text;
			}
		}
		private void lvSections_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(lvSections.SelectedItems.Count < 1)
				return;
			int nID = Convert.ToInt32(lvSections.SelectedItems[0].Tag.ToString());
			DB2MainForm.LoadSection(nID, ucSectionInfo1);
		}

		private void FormConfig_Load(object sender, System.EventArgs e)
		{
			lvSections.Items.Clear();
			checkBoxexamcode.Checked =  DB2MainForm.isDisplayExamCode;
			checkBoxSchool.Checked =  DB2MainForm.isDisplaySchool;
			checkBoxclass.Checked =  DB2MainForm.isDisplayClass;
			checkBoxpagenumber.Checked =  DB2MainForm.isDisplayPageNumber;
			txtPageDirection.Text = DB2MainForm.stPageDirection;
			txtReportFooter.Text = DB2MainForm.stReportFooter;
			txtReportHeader.Text = DB2MainForm.stReportHeader;
			DB2MainForm.LoadSections(lvSections);
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}
